﻿using FbHelperWP7NonUi.Settings;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace FbHelperNonUiTests
{
    [TestClass()]
    public sealed class TextStyleSettingsTest
    {
        #region Raise checking 

        [TestMethod()]
        public void SimpleTextStyleTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            CheckStyleEvents( target, target.SimpleTextStyle );

            bool wasRaised = false;

            target.StylesChangedEvent += () =>
            {
                wasRaised = true;
            };

            target.SimpleTextStyle = new StyleSettings();

            Assert.IsTrue( wasRaised );
        }

        [TestMethod()]
        public void Heading1TextStyleTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            CheckStyleEvents( target, target.Heading1Style );

            bool wasRaised = false;

            target.StylesChangedEvent += () =>
            {
                wasRaised = true;
            };

            target.Heading1Style = new StyleSettings();

            Assert.IsTrue( wasRaised );
        }

        [TestMethod()]
        public void Heading2TextStyleTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            CheckStyleEvents( target, target.Heading2Style );

            bool wasRaised = false;

            target.StylesChangedEvent += () =>
            {
                wasRaised = true;
            };

            target.Heading2Style = new StyleSettings();

            Assert.IsTrue( wasRaised );
        }

        [TestMethod()]
        public void Heading3TextStyleTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            CheckStyleEvents( target, target.Heading3Style );

            bool wasRaised = false;

            target.StylesChangedEvent += () =>
            {
                wasRaised = true;
            };

            target.Heading3Style = new StyleSettings();

            Assert.IsTrue( wasRaised );
        }

        #endregion 

        #region Null checking

        [TestMethod()]
        [ExpectedException( typeof( ArgumentNullException ) )]
        public void SimpleTextStyleNullTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            target.SimpleTextStyle = null;
        }

        private void CheckStyleEvents( TextStyleSettings target, StyleSettings styleSettings )
        {
            bool wasRaised = false;

            target.StylesChangedEvent += () =>
            {
                wasRaised = true;
            };

            styleSettings.FontSize += 1;

            Assert.IsTrue( wasRaised );
        }

        [TestMethod()]
        [ExpectedException( typeof( ArgumentNullException ) )]
        public void Heading1TextStyleNullTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            target.Heading1Style = null;
        }

        [TestMethod()]
        [ExpectedException( typeof( ArgumentNullException ) )]
        public void Heading2TextStyleNullTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            target.Heading2Style = null;
        }

        [TestMethod()]
        [ExpectedException( typeof( ArgumentNullException ) )]
        public void Heading3TextStyleNullTest()
        {
            TextStyleSettings target = new TextStyleSettings();

            target.Heading3Style = null;
        }

        #endregion
    }
}
